package ru.urfc.portal.model.accounting;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import ru.urfc.portal.model.SpectrObjectWithContragent;

@Table(name = "portal_balance")
@Entity
public class Balance extends SpectrObjectWithContragent implements BalanceOperation {
	private Integer year;
	private Integer month;
	@Transient
	private Integer day = 1;
	@Column(scale = 2, precision = 16, name = "saldo")
	private BigDecimal amount;
	
	public Balance() {
	}

	public Balance(Contragent contragent, Integer year, Integer month, BigDecimal amount) {
		this(contragent, year, month, 1, amount);
	}

	public Balance(Contragent contragent, Integer year, Integer month, Integer day, BigDecimal amount) {
		super(contragent);
		this.year = year;
		this.month = month;
		this.amount = amount;
		this.day = day;
	}

	@Override
	public BigDecimal getAmountWithSign() {
		return amount;
	}

	@Override
	public Date getDate() {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(0);
		calendar.set(year, month - 1, day, 0, 0, 0);
		return calendar.getTime();
	}

	@Override
	public String getName() {
		return "Остаток на начало периода";
	}
	
}
